#include "Alice/Systems/TextureRenderSys.h"
#include "Alice/Core/World.h"
#include "Alice/Components/TextureComp.hpp"
#include "Alice/Components/TransformComp.hpp"
#include "Alice/Components/ColorComp.hpp"

namespace Alice
{

void TextureRenderSys::Before()
{
    m_texture_renderer.Init();
}

void TextureRenderSys::OnUpdate()
{
    for (auto entity : entitys)
    {
        Scene& current_scene = world->GetCurrentScene();
        if (current_scene.entitys.find(entity) == 
            current_scene.entitys.end())
        {
            continue;
        }

        TextureComp& tex_comp = world->GetComp<TextureComp>(entity);
        TransformComp& trans_comp = world->GetComp<TransformComp>(entity);
        ColorComp& color_comp = world->GetComp<ColorComp>(entity);

        m_texture_renderer.Render(
            tex_comp.texture,
            trans_comp.position,
            trans_comp.size,
            trans_comp.rotate,
            color_comp.color
        );
    }
}

void TextureRenderSys::After()
{
    m_texture_renderer.Destroy();
}

} // namespace Alice
